<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <title>Vue示例</title>
</head>

<body>
<div id="app">
    <p>总数：{{total}}</p>
    <my-component v-model="total"></my-component>
    <button @click="handleReduce">-1</button>
</div>
<script charset="utf-8" src="../js/vue.min.js" type="text/javascript"></script>
<script type="text/javascript">
    Vue.component('my-component', {
        props: ['value'],
        template: '<input type="number" :value="value" @input="updateValue">',
        methods: {
            updateValue: function (event) {
                this.$emit('input', event.target.value);
            }
        }
    });

    var app = new Vue({
        el: '#app',
        data: {
            total: 0
        },
        methods: {
            handleReduce: function () {
                this.total--;
            }
        }
    })
</script>
</body>

</html>
